package logic

import (
	"context"
	"video/videorpc/videorpcclient"

	"video/api/internal/svc"
	"video/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type PasswordUpdateLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewPasswordUpdateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PasswordUpdateLogic {
	return &PasswordUpdateLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *PasswordUpdateLogic) PasswordUpdate(req *types.PasswordUpdateRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line

	passwordUpdate, err := l.svcCtx.VideoRpc.PasswordUpdate(l.ctx, &videorpcclient.PasswordUpdateRequest{
		Mobile:        req.Mobile,
		SendSms:       req.SendSms,
		NewPassword:   req.ReNewPassword,
		ReNewPassword: req.NewPassword,
	})

	if err != nil {
		return &types.Response{
			Message: err.Error(),
			Code:    500,
			Data:    nil,
		}, nil
	}

	return &types.Response{
		Message: "密码重置成功",
		Code:    200,
		Data:    passwordUpdate,
	}, nil

}
